package com.hjj.web.config;


import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * mybatis plus 配置
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.hjj.web.mapper") //扫描指定mapper接口包名注入bean
// @MapperScan("com.dongxin.**.service.*.mapper") //扫描指定mapper接口包名注入bean
public class MybatisPlusConfig {
    /**
     * 乐观锁
     * @return
     */
	@Bean
	public OptimisticLockerInterceptor optimisticLockerInterceptor() {
		return new OptimisticLockerInterceptor();
	}

	/**
	 * 分页插件
	 */
	@Bean
	public PaginationInterceptor paginationInterceptor() {
		return new PaginationInterceptor();
	}

	/**
	 * 逻辑删除
	 */
	@Bean
	public ISqlInjector sqlInjector() {
		return new LogicSqlInjector();
	}


	/**
	 * SQL执行效率插件(用于输出每条 SQL 语句及其执行时间)
	 */
//	@Bean
//	@Profile({ProfileConstants.PROFILE_DEV,ProfileConstants.PROFILE_TEST})// 设置 dev test 环境开启
//	public PerformanceInterceptor performanceInterceptor() {
//		return new PerformanceInterceptor();
//	}
}
